package com.controller.oos;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.DateUtils;
import com.common.http.HttpResult;
import com.service.oos.OosExcutorsService;
import com.model.oos.OosExcutorsModel;

/**
 * 
 */
@Controller("oosExcutorsController")
@RequestMapping(value = "/api")
public class OosExcutorsController {
	static final Logger logger = LoggerFactory.getLogger(OosExcutorsController.class);

	@Autowired
	OosExcutorsService oosExcutorsService;

	/**
	 * url映射
	 * @param map
	 * @return
	 */	
    @RequestMapping("qm/oos/excutors")
    public Map<String, String>  oosExcutors() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("key1", "value-1");
        return map;
    }
    
	/**
	 * 查询列表
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "qm/oos/excutors/selectList", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult selectList(@RequestParam Map<String, Object> map) {
		return oosExcutorsService.selectList(map);
	}

	/**
	 * 查询详情
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "qm/oos/excutors/selectInfor", method = { RequestMethod.GET })
	@ResponseBody
	public HttpResult selectInfor(@RequestParam String excId) {
		return oosExcutorsService.selectInfor(excId);
	}

	/**
	 * 保存询价
	 * 
	 * @param  
	 * @return
	 */
	@RequestMapping(value = "qm/oos/excutors/save", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult save(@RequestBody OosExcutorsModel oosExcutorsModel) {
		return oosExcutorsService.save(oosExcutorsModel);
	}
	
	/**
	 * 删除询价
	 * 
	 * @param  
	 * @return
	 */
	@RequestMapping(value = "qm/oos/excutors/delete", method = { RequestMethod.DELETE })
	@ResponseBody
	public HttpResult delete(@RequestParam String excId) {
		return oosExcutorsService.delete(excId);
	}

	/**
	 * 导出
	 * 
	 * @param map
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "qm/oos/excutors/export")
	public void export(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");
		String fileName = URLEncoder.encode("采购订单-" + DateUtils.getCurrentDate(), "UTF-8");
		response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
		oosExcutorsService.export(map, response);

	}
}
